package com.mashibing.singleton;

/**
 * 判断之后，给代码块加锁，任然不能解决线程安全问题
 * @author: Yuanzt
 * @Date: 2021/3/8
 */
public class Mgr05 {

    private static Mgr05 INSTANCE;

    private Mgr05(){}

    public static Mgr05 getInstance(){
        if (INSTANCE == null){
            synchronized (Mgr05.class){
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                INSTANCE = new Mgr05();
            }
        }
        return INSTANCE;
    }

    public static void main(String[] args) {
        for (int i=0;i<100;i++){
            new Thread(()-> System.out.println(Mgr05.getInstance().hashCode())).start();
        }
    }
}
